package name.fowler.refactoring.simplestore.reporter;

import java.util.List;

import name.fowler.refactoring.simplestore.Customer;
import name.fowler.refactoring.simplestore.Rental;
import name.fowler.refactoring.simplestore.service.*;

public class Reporter extends ReporterAbstract{
	
	public Reporter(FormaterInterface formater) {
		super(formater);
	}

	FormaterInterface m_formater;
	
	
	public String getCustomerDebt(Customer customer)
	{
        double totalAmount = 0;
		int frequentRenterPoints = 0;
        
        String result = "Rental record for " + customer.getM_Name() + "\n"; 

        List<Rental> m_Rentals = customer.getRentals();

        for(Rental each: m_Rentals) {
            double thisAmount = AmountService.getAmount(each);

            // Add frequent renter points
            frequentRenterPoints += FrequentPointsService.getBonus(each);


            // Show figures for this rental
            result += "\t" + each.getMovie().getM_Title() + "\t" + thisAmount + "\n";
            totalAmount += thisAmount;
        }

        // Add footer lines
        result += "Amount owed is " + totalAmount + "\n";
        result += "You earned " + frequentRenterPoints + " frequent renter points.";
        return result;
    }
	
	public String getAllDebts(List<Customer> customerList)
	{
		double totalAmount = 0;
        int frequentRenterPoints = 0;
        String result = "Rental records for all customers\n";
        
        for (Customer cust: customerList)  {
        
        result += "Rental record for " + cust.getM_Name() + "\n"; 

        List<Rental> m_Rentals = cust.getRentals();

        	for(Rental each: m_Rentals) {
        		double thisAmount = AmountService.getAmount(each);

        		// Add frequent renter points
        		frequentRenterPoints += FrequentPointsService.getBonus(each);


        		// Show figures for this rental
        		result += "\t" + each.getMovie().getM_Title() + "\t" + thisAmount + "\n";
        		totalAmount += thisAmount;
        	}
        }

        // Add footer lines
        result += "Amount owed is " + totalAmount + "\n";
        result += "You earned " + frequentRenterPoints + " frequent renter points.";
        return result;
    }
	
	public String getRentalDebt(Rental rental)
	{
        String result = "Get rental recont for rental";

   		double thisAmount = AmountService.getAmount(rental);

   		// Show figures for this rental
  		result += "\t" + rental.getMovie().getM_Title() + "\t" + thisAmount + "\n";

        // Add footer lines
        result += "Amount owed is " + thisAmount + "\n";
        return result;
    }
}
